{extend name="../../admin/view/main"}

{block name="content"}
<div class="think-box-shadow">
    <div id="TeamDataTree"></div>
    <script>
        (function (inst1) {
            // 加载指定用户下级
            function loaded(uuid) {
                var deferred = jQuery.Deferred();
                $.form.load('{:url("teams")}', {output: 'json', from: uuid}, 'get', function (ret) {
                        var data = [];
                        ret.data.list.forEach(function (item) {
                            data.push({
                                id: item.id, spread: true,
                                title: "<div class='notselect'>"
                                    + '[ <b>' + item.id + '</b> ] ' + (item.nickname || item.username || '-')
                                    + "<span class='color-blue'>【 " + item.subCount + " 】</span>"
                                    + "<span class='color-red'> ( <b>" + item.vip_name + "</b>" + " ) </span>"
                                    + (item.pid1 > 0 ? (item.pid0 > 0 ? '<span class="color-green">永久绑定</span>' : '<span class="color-red">临时绑定</span>') : "<span class='color-desc'>无推荐人</span>")
                                    + "<span class='color-blue'>【 累计充值 <b>" + (parseFloat(item.balance_total)) + "</b> 元，已使用 <b>" + parseFloat(item.balance_used) + "</b> 元，剩余可用 <b>" + (parseFloat((parseFloat(item.balance_total) - parseFloat(item.balance_used)).toFixed(2)) + 0) + "</b> 元 】</span>"
                                    + "<span class='color-green'>【 累计返利 <b>" + (parseFloat(item.rebate_total)) + "</b> 元（ 未到账 <b>" + parseFloat(item.rebate_lock) + "</b> 元），已提现 <b>" + parseFloat(item.rebate_used) + "</b> 元，剩余可提 <b>" + (parseFloat((parseFloat(item.rebate_total) - parseFloat(item.rebate_used)).toFixed(2)) + 0) + "</b> 元 】</span>"
                                    + "</div>",
                            });
                        });
                        return deferred.resolve(data), false;
                    }
                );
                return deferred;
            }

            // 加载一级数据
            loaded(0).then(function (data) {
                layui.tree.reload('TeamDataTree', {data: data});
            });

            // 初始化数据树
            inst1 = layui.tree.render({
                elem: '#TeamDataTree', id: 'TeamDataTree',
                click: function (obj) {
                    loaded(obj.data.id).then(function (data) {
                        obj.data.children = data;
                        inst1.reload();
                    });
                },
                data: []
            });
        })();
    </script>
</div>
{/block}
